<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>

<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>

<div id="app">
    <el-upload
            class="upload-demo"
            :on-preview="handlePreview"
            :on-success="onSuccess"
            drag
            action="/upload"
            multiple>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">只能上部分类型文件，且不超过100MB</div>
    </el-upload>
</div>

<script>
    new Vue({
        el:"#app",
        methods:{
            onSuccess(response, file, fileList){
                console.log(response)
                console.log(file)
                console.log(fileList)
                if (response.status !== "success"){
                    file.status = "error";
                    this.$message.error(response.msg);
                    for (var i = 0 ; i<fileList.length ;i++){
                        if (fileList[i] === file){
                            fileList.splice(i,1);
                        }
                    }
                }
            },
            handlePreview(file){
                console.log(file)
                if (window.open(file.response.url)){

                }

            }
        }
    })
</script>

</body>
</html>